using System.Collections.Generic;
using ContentRenderingApi.Exceptions;

namespace ContentRenderingApi
{
    /// <summary/>
    public class MemoryTemplate : AbstractTemplate
    {
        private Dictionary<string, string> _templates;

        /// <summary/>
        public MemoryTemplate(string name)
            : base(name)
        {
            this._templates = new Dictionary<string,string>();
        }

        /// <summary/>
        public void AddTemplate(string name, string template)
        {
            // error if the template already esxists
            if (this._templates.ContainsKey(name))
            {
                throw new TemplateAlreadyExistsException(name);
            }

            this._templates.Add(name, template);
        }

        /// <summary/>
        protected override string LoadTemplate(string name)
        {
            // error if the template does not exist
            if (!this._templates.ContainsKey(name))
            {
                throw new TemplateDoesNotExistException(name);
            }

            return this._templates[name];
        }
    }
}
